package cn.stylefeng.guns.modular.time.controller;

import cn.stylefeng.guns.modular.time.entity.Note;
import cn.stylefeng.guns.modular.time.model.request.NoteRequest;
import cn.stylefeng.guns.modular.time.service.NoteService;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@ApiResource(name = "记事本")
public class NoteController {

    @Resource
    private NoteService noteService;

    @GetResource(name = "分页查询笔记", path = "/note/page")
    public ResponseData<PageResult<Note>> page(NoteRequest request) {
        return new SuccessResponseData<>(noteService.findPage(request));
    }

    @PostResource(name = "新增笔记", path = "/note/add")
    public ResponseData<Void> add(@RequestBody @Validated(NoteRequest.add.class) NoteRequest request) {
        noteService.add(request);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "编辑笔记", path = "/note/edit")
    public ResponseData<Void> edit(@RequestBody @Validated(NoteRequest.edit.class) NoteRequest request) {
        noteService.edit(request);
        return new SuccessResponseData<>();
    }

    @PostResource(name = "删除笔记", path = "/note/delete")
    public ResponseData<Void> delete(@RequestBody @Validated(NoteRequest.delete.class) NoteRequest request) {
        noteService.delete(request);
        return new SuccessResponseData<>();
    }
}

